package com.learn.russianRoulette.entity;

import java.util.Random;

public class gun {
    private int bulletCount;
    private int bulletCountMax;

    public gun(int bulletCount, int bulletCountMax) {
        this.bulletCount = bulletCount;
        this.bulletCountMax = bulletCountMax;
    }

    public int getBulletCount() {
        return bulletCount;
    }

    public int getBulletCountMax() {
        return bulletCountMax;
    }

    public int[] gunSet(int bulletCount, int bulletCountMax) {
        if (bulletCount > bulletCountMax) {
            throw new IllegalArgumentException("子弹数不能大于最大子弹数");
        }

        int[] bullets = new int[bulletCountMax];
        Random random = new Random();

        // 先将需要的子弹数设置为1
        for (int i = 0; i < bulletCount; i++) {
            bullets[i] = 1;
        }

        // 打乱数组中的元素顺序
        for (int i = 0; i < bulletCountMax; i++) {
            int randomIndex = random.nextInt(bulletCountMax);
            int temp = bullets[i];
            bullets[i] = bullets[randomIndex];
            bullets[randomIndex] = temp;
        }
        return bullets;
    }
}
